package com.example.gymmanagebackend.mapper;

import com.example.gymmanagebackend.pojo.CourseReservation;
import org.apache.ibatis.annotations.*;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.Date;
import java.util.List;

@Mapper
public interface CourseReservationMapper {
    @Insert("INSERT INTO CourseReservation (course_id, courseName, coachName, username, reservationTime, reservation_date) VALUES (#{courseId}, #{courseName}, #{coachName}, #{username}, #{reservationTime}, #{reservationDate})")
    @Options(useGeneratedKeys = true, keyProperty = "reservationId")
    int addCourseReservation(CourseReservation reservation);

    @Select("SELECT * FROM CourseReservation WHERE username = #{username}")
    List<CourseReservation> getCourseReservationsByUsername(String username);

    @Delete("DELETE FROM CourseReservation WHERE courseName = #{courseName} AND reservationTime = #{reservationTime}")
    int deleteCourseReservationByCondition(@Param("courseName") String courseName, @Param("reservationTime") String reservationTime);

    @Select("SELECT COUNT(*) FROM CourseReservation WHERE username = #{username} AND courseName = #{courseName} AND reservation_date = #{reservationDate}")
    int checkCourseReservationExists(@Param("username") String username, @Param("courseName") String courseName, @Param("reservationDate") Date reservationDate);
    @Select("SELECT * FROM CourseReservation WHERE course_id IS NOT NULL")
    List<CourseReservation> getAllCourseReservations();

    @Select("SELECT courseName, COUNT(*) AS count FROM CourseReservation GROUP BY courseName")
    List<CourseReservation> getCourseReservationCount();

    @Select("SELECT cr.courseName, m.gender, COUNT(*) AS count FROM CourseReservation cr JOIN Members m ON cr.username = m.name GROUP BY cr.courseName, m.gender")
    List<CourseReservation> getCourseGenderDistribution();
}